package com.itheima.controller;

import com.itheima.domain.dto.StudentDto;
import com.itheima.domain.pojo.Student;
import com.itheima.domain.vo.PageResult;
import com.itheima.domain.vo.Result;
import com.itheima.domain.vo.StudentVo;
import com.itheima.service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/** Student-学员管理
 * @author 上官徵羽
 * @version 1.0
 * @since 2025-08-21 9:54
 */
@RestController
@Slf4j
@RequestMapping("/students")
public class StudentController {

    @Autowired
    private StudentService studentService;
    /** 分页查询学员列表 */
    @GetMapping
    public Result getStudentPage(StudentDto studentDto){
        PageResult<StudentVo> pageResult = studentService.getStudentPage(studentDto);
        return Result.success(pageResult);
    }

    /** 批量删除学员 */
    @DeleteMapping("/{ids}")
    public Result deleteStudent(@PathVariable Integer[] ids){
        studentService.deleteStudent(ids);
        return Result.success();
    }

    /** 添加学员 */
    @PostMapping
    public Result addStudent(@RequestBody Student student){
        studentService.addStudent(student);
        return Result.success();
    }
    /** 根据id查询学员 */
    @GetMapping("/{id}")
    public Result getStudentId(@PathVariable("id") Integer id){
        Student student = studentService.getStudentId(id);
        return Result.success(student);
    }

    /** 修改学员 */
    @PutMapping
    public Result updateStudent(@RequestBody Student student){
        studentService.updateStudent(student);
        return Result.success();
    }

    /** 违纪扣分 */
    @PutMapping("/violation/{id}/{score}")
    public Result pointsWillBeDeductedForDisciplinaryViolations(Integer score, Integer id){
        studentService.pointsWillBeDeductedForDisciplinaryViolations(score, id);
        return Result.success();
    }
}
